<?php

namespace App\Http\Middleware;

use Closure;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class AdminPermission
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {

        $user = $request->user();
        $route = $request->route()->uri();
        $res = $user->can($route);
        if(!$res){
            return response()->json(['message' => '权限不足'])
                ->setStatusCode(201);
        }
        return $next($request);
    }
}
